package cn.com.justing.pigeon.feed;

import java.io.IOException;
import java.net.MalformedURLException;
import java.util.Date;
import java.util.List;

import org.gnu.stealthp.rsslib.RSSException;
import org.gnu.stealthp.rsslib.RSSItem;

import cn.com.justing.pigeon.shortener.MessageGenerator;
import cn.com.justing.pigeon.shortener.MessageGeneratorImpl;

import com.sun.syndication.io.FeedException;

public class FeedTester
{

	/**
	 * @param args
	 * @throws FetcherException
	 * @throws FeedException
	 * @throws IOException
	 * @throws MalformedURLException
	 * @throws IllegalArgumentException
	 * @throws RSSException
	 * @throws MalformedURLException
	 */
	public static void main(String[] args) throws IllegalArgumentException,
			MalformedURLException, RSSException

	{
		String feedString = "http://www.justing.com.cn/justrss/justrss.xml";
		String feedString2 = "http://www.justing.com.cn/justrss/justrss_album_gaoduan.xml";
		String feedString3 = "http://www.justing.com.cn/justrss/justrss_album_jingpindiancang.xml";
		String test = "http://blog.sina.com.cn/rss/drpickup.xml";

		// try
		// {
		// URL feedUrl = new URL(feedString3);
		// SyndFeedInput input = new SyndFeedInput();
		// System.out.println("Start");
		// SyndFeed feed = input.build(new XmlReader(feedUrl));
		// // 通过url地址和XmlReader进行解释，自动识别xml的类型
		// System.out.println(feed);
		//
		// } catch (Exception ex)
		// {
		// ex.printStackTrace();
		// }
		long time = System.currentTimeMillis();

		// FeedFetcherImpl fetcher = new FeedFetcherImpl(new URL(feedString3));
		FeedFetcherImpl fetcher = new FeedFetcherImpl("justing.xml");
		fetcher
				.setUpdatedDate(new Date(Date.parse("23 Mar 2010 16:20:10 GMT")));
		List<RSSItem> list = fetcher.getNewFeeds();
		MessageGenerator mGenerator = new MessageGeneratorImpl();
		for (int i = 0; i < list.size(); i++)
		{
			System.out.println(i + ":" + mGenerator.getMessage(list.get(i)));
		}
		System.out.println(fetcher.getUpdatedDate());
		System.out.println(System.currentTimeMillis() - time);
	}
}
